//
//  KZMedifyNicknameVC.swift
//  BoyeStore
//
//  Created by 朱凯 on 2018/6/28.
//  Copyright © 2018年 itboye. All rights reserved.
//

import UIKit

class KZMedifyNicknameVC: KZBaseViewControllerWithBack {
    
    let nickTf = UITextField()
    var saveSuccessClouse: (String)->Void = {_ in}

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationItem.title = "修改昵称"
        view.backgroundColor = kBgColor
        setupUI()
    }


    func setupUI() {
        
        let whiteView = UIView()
        whiteView.backgroundColor = UIColor.white
        view.addSubview(whiteView)
        whiteView.snp.makeConstraints { (m) in
            m.top.equalTo(10)
            m.left.right.equalTo(0)
            m.height.equalTo(44)
        }
        
        let titleLabel = UILabel()
        titleLabel.textColor = UIColor.black
        titleLabel.textAlignment = .left
        titleLabel.text = "昵称"
        titleLabel.font = UIFont.systemFont(ofSize: 14)
        view.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (m) in
            m.left.equalTo(15)
            m.top.bottom.equalTo(whiteView)
        }
        
        nickTf.textColor = kThemeColor
        nickTf.textAlignment = .left
        nickTf.placeholder = "请输入昵称"
        nickTf.font = UIFont.systemFont(ofSize: 14)
        view.addSubview(nickTf)
        nickTf.snp.makeConstraints { (m) in
            m.right.equalTo(-15)
            m.top.bottom.equalTo(whiteView)
            m.left.equalTo(titleLabel.snp.right).offset(15)
        }
        
        let saveButton = UIButton(type: .custom)
        saveButton.addTarget(self, action: #selector(onSave), for: .touchUpInside)
        saveButton.backgroundColor = kYellowColor
        saveButton.layer.cornerRadius = 4
        saveButton.titleLabel?.font = kFont(14)
        saveButton.layer.masksToBounds = true
        saveButton.setTitle("保存", for: .normal)
        saveButton.setTitleColor(UIColor.white, for: .normal)
        view.addSubview(saveButton)
        saveButton.snp.makeConstraints { (m) in
            m.width.equalTo(view).multipliedBy(0.5)
            m.height.equalTo(36)
            m.centerX.equalToSuperview()
            m.top.equalTo(whiteView.snp.bottom).offset(80)
        }
        
    }
}

extension KZMedifyNicknameVC {
    
    @objc func onSave() {
        
        saveSuccessClouse(nickTf.text!)
        self.navigationController?.popViewController(animated: true)
    }
}
